<template>
  <div>
    <j-modal
    :title="title"
    :width="width"
    :confirmLoading="confirmLoading"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-row>
          <a-col>
            <a-form-model-item 
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="初盘单号" 
              prop="billNo">
              <j-search-select-tag placeholder="请输入" v-model="model.billNo" :dictOptions="searchOptions" mode="multiple">
              </j-search-select-tag>
              <!-- <a-input placeholder="请输入" v-model="model.billNo"></a-input> -->
            </a-form-model-item>
          </a-col>
          <a-col>
            <a-form-model-item
              prop="endTime"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="异常复盘结束时间">
              <a-date-picker showTime valueFormat="YYYY-MM-DD HH:mm:ss" v-model="model.endTime" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-modal>
  </div>
</template>

<script>
  import moment from "moment"
  import { httpAction,getAction } from '@/api/manage'
  export default {
    name: 'AssetAgainModal',
    components: {
    },
    props: {
    },
    data () {
      return {
        visible: false,
        confirmLoading: false,
        disableSubmit:false,
        searchOptions:[],
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        title:'',
        width:800,
        visible: false,
        disableSubmit: false,
        url: {
          add: "/assets/assetsDoubleQuotationResult/startAssets",
          list:"/assets/assetsPreliminaryResults/list"
        }
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      },
      validatorRules(){
        return{
            billNo: [{ required: true, message: '请输入初盘单号!' }],
            endTime: [{ required: true, message: '请选择结束时间!' }],
        }
      }
    },
    created() {
     //备份model原始值
      // this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      moment,
      // 新增
      add () {
        // this.visible=true
        this.edit({});
        // this.$nextTick(()=>{
        //   this.$refs.realForm.add();
        // })
        // this.edit(this.modelDefault);
      },
      // 编辑、详情
      edit(record) {
        console.log('333')
        console.log(record)
        this.model = Object.assign({}, record);
        this.visible=true
        this.billNoHandle()
        
        // this.$nextTick(()=>{
        //   this.$refs.realForm.edit(record);
        // })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
      handleOk () {
        const that = this;
        // 触发表单验证
         this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            console.log('2222')
            console.log(this.model)
            
            httpAction(this.url.add,this.model,'post').then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false;
          }
        })
      },
      billNoHandle(){
        const that = this
        console.log('777777')
        const params = {
          ...this.model,
          pageSize: '100'
        }
        getAction(this.url.list,params).then((res)=>{
          console.log(res)
          this.searchOptions = res.result.records.map(item=>{
            return{
              ...item,
              text:item.billNo+'-'+item.deptName,
              value:item.billNo
            }
          })
          console.log(this.searchOptions)
          
          
        })
      }
    }
  }
</script>
<style scoped>
  .toolBt{
    display: flex;
    align-content: center;
  }
</style>